/**
 * Created by truncate on 2017/9/30.
 * Author: 带鞋拖地
 * QQ: 327056088
 *
 * 《江畔独步寻花》· 杜甫
 * 黄四娘家花满蹊，千朵万朵压枝低。
 * 留连戏蝶时时舞，自在娇莺恰恰啼。
 * 网络请求封装库
 */

class LoginInfo {
}

/**
 * 注册VUE插件
 * @param Vue
 */
LoginInfo.install = function (Vue) {
  /**
   * 全局请求接口
   * @param method 方法
   * @param opts 参数
   * @param toast 是否提示
   * @returns {string}

   * 用户名
   @ApiModelProperty(notes = "用户名")
   private String userName;
   @ApiModelProperty(notes = "所属车队")
   private String orgId;
   @ApiModelProperty(notes = "所属车队名")
   private String orgName;
   @ApiModelProperty(notes = "机构LOGO图片地址")
   private String logoPath;
   @ApiModelProperty(notes = "用户ID")
   private Long userId;
   @ApiModelProperty(notes = "所属部门")
   private Long dptId;
   @ApiModelProperty(notes = "用户名昵称")
   private String userNickName;
   @ApiModelProperty(notes = "用户权限标识")
   Set<String> perms;
   @ApiModelProperty(notes = "用户jwt串")
   private String token;
   */
  Vue.prototype.getLoginInfo = function () {
    let info = window.sessionStorage.getItem('loginInfo');
    if (info !== null) {
      let loginInfo = JSON.parse(info);
      return loginInfo;
    }
    return {};
  };
  Vue.prototype.hasPermission = function (permission) {
    let info = window.sessionStorage.getItem('loginInfo');
    if (info === null) {
      return false;
    }
    let loginInfo = JSON.parse(info);
    let permsSet = loginInfo.perms;
    var flag = false;
    for (var i = 0; i < permsSet.length; i++) {
      if (permsSet[i] === permission) {
        flag = true;
        break;
      }
    }
    return flag;
  };
  Vue.prototype.loginToken = function () {
    let token = window.sessionStorage.getItem('loginToken');
    return token;
  };
};
export default LoginInfo;
